<div navbar ng-init="currentItem='utils.user'"></div>
<div ng-show="!loaded">
    <div loading></div>
</div>

<div id="main" ng-show="loaded" style="display:none">
    <div class="module-header">
        <h3>用户管理</h3>
    </div>

    <div class="tabbable">
        <ul class="nav nav-tabs">
            <li ng-class="'active' | iftrue:activeTabName=='user'"><a href="#user" ng-click="tab_sec('user')" data-toggle="tab">用户</a></li>
            <li ng-class="'active' | iftrue:activeTabName=='group'"><a href="#group" ng-click="tab_sec('group')" data-toggle="tab">用户组</a></li>
            <li class="pull-right" ng-show="activeTabName=='user'">
                <button class="btn btn-default btn-sm" title="当前用户数量" ng-show="users && users.length">数量: {{users.length}}</button>
                <div class="btn-group btn-group-sm">
                    <button class="btn btn-default" ng-click="loadUsers()" title="刷新用户列表"><i class="glyphicon glyphicon-refresh"></i></button>
                    <button class="btn btn-default" ng-click="useraddconfirm()" title="添加新用户"><i class="glyphicon glyphicon-plus"></i></button>
                </div>
            </li>
            <li class="pull-right" ng-show="activeTabName=='group'">
                <button class="btn btn-default btn-sm" title="当前用户组数量" ng-show="groups && groups.length">数量: {{groups.length}}</button>
                <div class="btn-group btn-group-sm">
                    <button class="btn btn-default" ng-click="loadGroups()" title="刷新用户组列表"><i class="glyphicon glyphicon-refresh"></i></button>
                    <button class="btn btn-default" ng-click="groupaddconfirm()" title="添加新用户组"><i class="glyphicon glyphicon-plus"></i></button>
                </div>
            </li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane table-responsive" ng-class="'active' | iftrue:activeTabName=='user'" id="user" ng-init="loadUsers()">
                <div ng-show="loading.user"><div waiting></div></div>
                <table ng-hide="loading.user" class="table table-hover table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th style="width:50px" class="text-right">ID</th>
                            <th style="width:40px">状态</th>
                            <th>用户名</th>
                            <th>备注</th>
                            <th>用户组</th>
                            <th>主目录</th>
                            <th>SHELL路径</th>
                            <th style="width:130px">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="user in users">
                            <td class="text-right">{{user.pw_uid}}</td>
                            <td ng-bind-html-unsafe="user.lock | user.lock"></td>
                            <td>{{user.pw_name}}</td>
                            <td>{{user.pw_gecos}}</td>
                            <td>{{user.pw_gname}}</td>
                            <td>{{user.pw_dir}}</td>
                            <td>{{user.pw_shell}}</td>
                            <td>
                                <button class="btn btn-default btn-xs" ng-click="usermodconfirm($index)">修改</button>
                                <button class="btn btn-default btn-xs" ng-click="userdelconfirm($index)">删除</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="tab-pane table-responsive" ng-class="'active' | iftrue:activeTabName=='group'" id="group" ng-init="loadGroups()">
                <div ng-show="loading.group"><div waiting></div></div>
                <table ng-hide="loading.group" class="table table-hover table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th style="width:50px" class="text-right">ID</th>
                            <th>用户组</th>
                            <th>组成员</th>
                            <th style="width:260px">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="group in groups">
                            <td class="text-right">{{group.gr_gid}}</td>
                            <td>{{group.gr_name}}</td>
                            <td><span ng-repeat="member in group.gr_mem">{{member}}<span ng-show="$index<group.gr_mem.length-1">, </span></span>
                            </td>
                            <td>
                                <button class="btn btn-default btn-xs" ng-click="groupmodconfirm($index)">修改</button>
                                <button class="btn btn-default btn-xs" ng-click="groupdelconfirm($index)">删除</button>
                                <button class="btn btn-default btn-xs" ng-click="groupmemsaddconfirm($index)">添加成员</button>
                                <button class="btn btn-default btn-xs" ng-click="groupmemsdelconfirm($index)" ng-disabled="group.gr_mem.length==0">删除成员</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>

<div id="useraddconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">添加新用户</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">用户名：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curuser.pw_name">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curuser.pw_gecos">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">用户组：</label>
                        <div class="col-sm-9">
                            <select class="form-control" ng-model="curuser.pw_gname" ng-options="group.gr_name as group.gr_name for group in groups"></select>
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">主目录：</label>
                        <div class="col-sm-9 checkbox">
                            <label>
                                <input type="checkbox" ng-model="curuser.createhome"> 是否创建主目录<span ng-show="curuser.pw_name"> /home/{{curuser.pw_name}}</span>？
                            </label>
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">SHELL路径：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curuser.pw_shell">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">锁定帐户：</label>
                        <div class="col-sm-9 checkbox">
                            <label><input type="checkbox" ng-checked="curuser.lock"> 是否锁定该帐户？</label>
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label" for="add_passwd">密码：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="password" id="add_passwd" ng-model="curuser.pw_passwd" placeholder="如不想设置密码，请留空" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label" for="add_passwdc">确认密码：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="password" id="add_passwdc" ng-model="curuser.pw_passwdc" placeholder="如不想设置密码，请留空" autocomplete="off">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#useraddconfirm').modal('hide')" ng-click="useradd()">添加</button>
            </div>
        </div>
    </div>
</div>

<div id="usermodconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">修改用户 {{curuser.pw_name}}</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curuser.pw_gecos">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">用户组：</label>
                        <div class="col-sm-9">
                            <select class="form-control" ng-model="curuser.pw_gname" ng-options="group.gr_name as group.gr_name for group in groups"></select>
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">主目录：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curuser.pw_dir">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">SHELL路径：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curuser.pw_shell">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">锁定帐户：</label>
                        <div class="col-sm-9 checkbox">
                            <label><input type="checkbox" ng-model="curuser.lock"> 是否锁定该帐户？</label>
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label" for="mod_passwd">修改密码：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="password" id="mod_passwd" ng-model="curuser.pw_passwd" placeholder="如不想修改密码，请留空" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label" for="mod_passwdc">确认密码：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="password" id="mod_passwdc" ng-model="curuser.pw_passwdc" placeholder="如不想修改密码，请留空" autocomplete="off">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#usermodconfirm').modal('hide')" ng-click="usermod()">确定</button>
            </div>
        </div>
    </div>
</div>

<div id="userdelconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">删除用户 {{curuser.pw_name}}</h3>
            </div>
            <div class="modal-body">
                <p>确定要删除用户 {{curuser.pw_name}} 吗？</p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-danger" onclick="$('#userdelconfirm').modal('hide')" ng-click="userdel()">确认删除</button>
            </div>
        </div>
    </div>
</div>

<div id="groupaddconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">添加新用户组</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">用户组名称：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curgrp_name">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#groupaddconfirm').modal('hide')" ng-click="groupadd()">添加</button>
            </div>
        </div>
    </div>
</div>

<div id="groupmodconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">修改用户组 {{curgrp_name}}</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">用户组名称：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" ng-model="curgrp_newname">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#groupmodconfirm').modal('hide')" ng-click="groupmod()">修改</button>
            </div>
        </div>
    </div>
</div>

<div id="groupdelconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">删除用户组 {{curgrp_name}}</h3>
            </div>
            <div class="modal-body">
                <p>确定要删除用户组 {{curgrp_name}} 吗？</p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-danger" onclick="$('#groupdelconfirm').modal('hide')" ng-click="groupdel()">确认删除</button>
            </div>
        </div>
    </div>
</div>

<div id="groupmemsaddconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">向组 {{curgrp_name}} 中添加成员</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">要添加的成员：</label>
                        <div class="col-sm-9">
                            <select class="form-control" ng-model="curgrp_mem" ng-options="user.pw_name as user.pw_name for user in users"></select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#groupmemsaddconfirm').modal('hide')" ng-click="groupmemsadd()">确认添加</button>
            </div>
        </div>
    </div>
</div>

<div id="groupmemsdelconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">删除组 {{curgrp_name}} 中的成员</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group form-inline">
                        <label class="col-sm-3 control-label">要删除的成员：</label>
                        <div class="col-sm-9">
                            <select class="form-control" ng-model="curgrp_mem" ng-options="member for member in curgrp_mems"></select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-danger" onclick="$('#groupmemsdelconfirm').modal('hide')" ng-click="groupmemsdel()">确认删除</button>
            </div>
        </div>
    </div>
</div>